//
//  YYMineInfoView.m
//  Project
//
//  Created by Yown on 2024/2/5.
//

#import "YYMineInfoView.h"
#import "YYMineCell.h"

#import <BIToolModule/BIImagePicker.h>
#import <BIProjectModule/BIProjectContext.h>
#import <BIToolModule/BIProjectDefine.h>
#import <BIRouteModule/BIRouteManager.h>
#import <BIProjectModule/BITableView.h>
#import <BIToolModule/BIAlertAction.h>

#import <BIProjectModule/BIAppDefine.h>
#import <BIToolModule/UIView+Custom.h>
#import <BIToolModule/NSArray+Helper.h>

#import <SDWebImage/SDWebImage.h>

@interface YYMineInfoView () <UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet BITableView *tableView;
@property (nonatomic, copy) NSArray *cellArray;

@end

@implementation YYMineInfoView

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.backgroundColor = [UIColor loadColorFromString:@"#F6F6F6"];
    
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.bounces = NO;
    [self.tableView registerNib:[UINib nibWithNibName:@"YYMineCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:[YYMineCell cellIdentifier]];
}

- (void)reloadView:(NSArray *)cellArray {
    self.cellArray = cellArray;
    [self.tableView reloadData];
}

#pragma mark - Action

- (void)clickHeaderView {
    BIUserModel *user = [BIProjectContext sharedInstance].user;
    if ([user isLogin]) {
        [[BIRouteManager sharedInstance] openVCCMD:@"mine_info" isPresent:NO arguments:nil];
    } else {
        [[BIProjectContext sharedInstance] openLoginVCWithSucceedBlock:nil];
    }
}

#pragma mark - UITableView

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.cellArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [YYMineCell cellHeight];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YYMineCellModel *model = [self.cellArray safeObjectAtIndex:indexPath.row];
    YYMineCell *cell = [tableView dequeueReusableCellWithIdentifier:[YYMineCell cellIdentifier] forIndexPath:indexPath];
    [cell setupModel:model];
    if (indexPath.row == 0) {
        [cell adjustArrowWidth:40];
    } else {
        [cell adjustArrowWidth:20];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
//        [BIImagePicker openImagePickerAndCameraActionSheet:^(BIImagePickerActionSheetSelectedStyle selectedStyle) {
//            if (selectedStyle == BIImagePickerActionSheetCameraStyle) {
//                [BIImagePicker openCameraWithCompletionBlock:^(UIImage *image) {
//
//                }];
//            } else if (selectedStyle == BIImagePickerActionSheetPhotoStyle) {
//                [BIImagePicker openImagePickerVCWithImageCount:1 isCrop:NO selectedBlock:^(NSArray *images) {
//
//                }];
//            }
//        }];
    } else {
//        [BIAlertAction showAlertWithTextField:nil message:BILocalizedString(@"mine_nickname_placeholder") clickDoneBlock:^(NSString *text) {
//
//        }];
    }
}


@end
